package com.canal.starter.event;

import com.alibaba.otter.canal.protocol.CanalEntry;

import java.util.Objects;

/**
 * DefaultCanalEventListener
 *
 * @author chen.qian
 * @date 2018/3/19
 */
public interface DmlCanalEventListener extends CanalEventListener {
    /**
     * 方法功能描述
     *
     * @param eventType
     * @param rowData
     */
    @Override
    default void onEvent(CanalEntry.EventType eventType, CanalEntry.RowData rowData) {
        Objects.requireNonNull(eventType);
        switch (eventType) {
            case INSERT:
                this.onInsert(rowData);
                break;
            case UPDATE:
                this.onUpdate(rowData);
                break;
            case DELETE:
                this.onDelete(rowData);
                break;
            default:
                break;
        }
    }

    /**
     * fired on insert event
     *
     * @param rowData rowData
     */
    void onInsert(CanalEntry.RowData rowData);

    /**
     * fired on update event
     *
     * @param rowData rowData
     */
    void onUpdate(CanalEntry.RowData rowData);

    /**
     * fired on delete event
     *
     * @param rowData rowData
     */
    void onDelete(CanalEntry.RowData rowData);
}
